package com.softline.documentsmall.controller;

import com.softline.documentsmall.entity.SpecialDictionary;
import com.softline.documentsmall.entity.SpecialDictionaryVO;
import com.softline.documentsmall.ret.ReturnVO;
import com.softline.documentsmall.ret.ReturnVOUtils;
import com.softline.documentsmall.service.SpecialDictionaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: documentsmall
 * @description: 特色词条
 * @author: wmj
 * @create: 2020-12-07
 * @ClassName: SpecialDictionaryController
 */
@Api(value="特色词条相关接口",tags={"特色词条相关接口"})
@RestController
@RequestMapping("/special/dictionary")
@CrossOrigin(allowCredentials = "true",allowedHeaders = "*")
public class SpecialDictionaryController {

    @Autowired
    SpecialDictionaryService specialDictionaryService;

    @ApiOperation(value="特色词条列表页", notes = "特色词条列表页")
    @GetMapping(value = "/listByLanguage")
    public ReturnVO listByLanguage(@RequestParam(name = "type",defaultValue = "en")String type){
        List<SpecialDictionaryVO> list = specialDictionaryService.listByLanguage(type);
        return ReturnVOUtils.success(list);
    }

    @ApiOperation(value="特色词条新增", notes = "特色词条新增")
    @PostMapping(value = "/add")
    public ReturnVO add(@RequestBody SpecialDictionary specialDictionary){
        int add = specialDictionaryService.add(specialDictionary);
        if(add == 1){
            return ReturnVOUtils.success("新增成功");
        }else {
            return ReturnVOUtils.businessFailCustom(201,"特殊词条已存在");
        }
    }

    @ApiOperation(value="特色词条删除", notes = "特色词条删除")
    @DeleteMapping(value = "/delete")
    public ReturnVO delete(@RequestParam("id") Integer id){
        specialDictionaryService.delete(id);
        return ReturnVOUtils.success("删除成功");
    }
}
